//
//  LastMonBillViewController.m
//  TengyunStation
//
//  Created by Johnny on 15/8/27.
//  Copyright (c) 2015年 xingrong. All rights reserved.
//

#import "LastMonBillViewController.h"
#import "SocketMethod.h"
#import "Singleton.h"

@interface LastMonBillViewController ()

@end

@implementation LastMonBillViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"上月账单";
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    if ([Singleton shareInstance].userMessage.websiteIsSend) {
        float height = [UIScreen mainScreen].bounds.size.height - 44 - 64;
        _multipleTabView = [[MultipleTabView alloc] initWithFrame:CGRectMake(0, 0, 320, 38)];
        _multipleTabView.tabArray = @[@"自提件", @"上门件"];
        _multipleTabView.delegate = self;
        [self.view addSubview:_multipleTabView];
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 44, 320, height)];
        _scrollView.delegate = self;
        _scrollView.pagingEnabled = YES;
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.showsVerticalScrollIndicator = NO;
        _scrollView.bounces = NO;
        [self.view addSubview:_scrollView];
        _scrollView.contentSize = CGSizeMake(320 * 2, height);
        MonthBillView *zitiBillView = [[MonthBillView alloc] initWithFrame:CGRectMake(0, 0, 320, height) SearchTime:[SocketMethod getLastMonTypeyyyyMM] SearchType:@"01"];
        [_scrollView addSubview:zitiBillView];
        MonthBillView *visitBillView = [[MonthBillView alloc] initWithFrame:CGRectMake(320, 0, 320, height) SearchTime:[SocketMethod getLastMonTypeyyyyMM] SearchType:@"02"];
        [_scrollView addSubview:visitBillView];
    } else {
        float height = [UIScreen mainScreen].bounds.size.height - 64;
        MonthBillView *zitiBillView = [[MonthBillView alloc] initWithFrame:CGRectMake(0, 0, 320, height) SearchTime:[SocketMethod getThisMonTypeyyyyMM] SearchType:@"01"];
        [self.view addSubview:zitiBillView];
    }
    
    [self handelNetWorkMethod];
}

#pragma mark MultipleTabViewDelegate
- (void)buttonClickIndex:(NSInteger)currentIndex {
    [_scrollView setContentOffset:CGPointMake(320 * currentIndex, 0) animated:YES];
    if (currentIndex == 0) {
        _scrollView.bounces = NO;
    } else {
        _scrollView.bounces = YES;
    }
}

#pragma mark UIScrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    NSInteger index = (NSInteger)scrollView.contentOffset.x/320;
    _multipleTabView.index = index;
    if (index == 0) {
        _scrollView.bounces = NO;
    } else {
        _scrollView.bounces = YES;
    }
}

@end
